package com.facebook.presto.tdengine;

import com.facebook.presto.spi.connector.*;
import com.facebook.presto.spi.transaction.IsolationLevel;

public class TdEngineConnector implements Connector {

    private TdEngineMetadata metadata;
    private TdEngineSplitManager splitManager;
    private TdEngineRecordSetProvider recordSetProvider;

    public TdEngineMetadata getMetadata() {
        return metadata;
    }

    public void setMetadata(TdEngineMetadata metadata) {
        this.metadata = metadata;
    }

    public void setSplitManager(TdEngineSplitManager splitManager) {
        this.splitManager = splitManager;
    }

    public void setRecordSetProvider(TdEngineRecordSetProvider recordSetProvider) {
        this.recordSetProvider = recordSetProvider;
    }

    public TdEngineConnector(String url, String catalogName) throws Exception {

        TdUtil.init(url);
        this.metadata = TdEngineMetadata.getInstance();
        this.splitManager = TdEngineSplitManager.getInstance();
        this.recordSetProvider = TdEngineRecordSetProvider.getInstance();
    }

    @Override
    public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly) {
        return TdEngineTransactionHandle.INSTANCE;
    }

    // 该对象定义了需要连接的数据源所有信息（schema，tables，table，column，columnType等）
    @Override
    public ConnectorMetadata getMetadata(ConnectorTransactionHandle transactionHandle) {
        return metadata;
    }

    //该对象定义了数据源的切片split
    @Override
    public ConnectorSplitManager getSplitManager() {
        return splitManager;
    }

    //该对象是实际读取数据源的对象，所有数据读的操作到这在里面。
    @Override
    public ConnectorRecordSetProvider getRecordSetProvider() {
        return recordSetProvider;
    }
}
